package com.yyy.lambda;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * return 在forecach中相当于for循环中的continue
 * 只会跳过当前的循环
 */
public class TestReturn {


    @Test
    public void test1() {
        test();
    }

    private void test() {
        List<String> list = createList();
        list.forEach(item -> {
            if (item.equals("hello5")) {
                return;
            }
            System.out.println(item);
        });


    }

    private List<String> createList() {

        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add("hello" + i);
        }
        return list;
    }
}
